package com.atqinke.designpattern.creationtype.singlecase;

/**
 * @BelongsProject: BasicConnection
 * @BelongsPackage: com.atqinke.DesignPattern.creation.SingleCase
 * @Author: NieHk
 * @CreateTime: 2022-08-16  09:31
 * @Description: 饿汉式单例模式实现1
 * @Version: 1.0
 */
public class Hungry {
    //私有构造器
    private Hungry(){}
    //创建对象
    private static Hungry hungry = new Hungry();
    //提供获取方式
    public static Hungry getHungry(){
        return hungry;
    }

}

/**
* @description: 饿汉式单例模式实现2
* @author: NieHK
* @date: 2022/8/16 9:37
* @param
* @return:
*/
class HungryTwo{
    //私有构造器
    private HungryTwo(){}
    //声明变量
    private static HungryTwo hungryTwo;
    //创建对象
    static {
        hungryTwo = new HungryTwo();
    }
    //提供获取方式
    public static HungryTwo getHungryTwo(){
        return hungryTwo;
    }


}
